package com.app.business.service.uni;

import com.app.business.model.CarLot;
import com.app.business.model.House;
import com.app.business.model.YxCarLot;
import com.app.business.model.YxHouse;
import com.app.system.jpa.JpaBaseDao;
import com.app.system.utils.dataType.BigDecimalUtils;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 房屋预选信息业务表
 */
@Service
@SuppressWarnings("all")
public class AppYxCarLotService extends JpaBaseDao<YxCarLot,Integer> {

    /**
     * 删除预选方案--车位
     *
     * @param houseId
     * @param contractId
     */
    @Transactional
    public synchronized void deleteYxCatLot(Integer carLotId, Integer contractId) {
        String sql = "delete from yx_car_lot  where car_lot_id =:carLotId and contract_id =:contractId";
        this.entityManager.createNativeQuery(sql).setParameter("carLotId", carLotId).setParameter("contractId", contractId).executeUpdate();
    }

    /**
     * 预选车位List
     *
     * @param contractId
     * @return
     */
    public List<CarLot> getYxCarLotList(Integer contractId) {
        StringBuffer hql = new StringBuffer(" from CarLot cl  where cl.id ");
        hql.append(" in (select yx.carLotId from YxCarLot yx where yx.contractId =:contractId)");
        List<CarLot> carLotList = entityManager.createQuery(hql.toString()).setParameter("contractId", contractId).getResultList();
        return carLotList;
    }

    /**
     * 得到contractId对应下的carlotId
     *
     * @param contractId
     * @return
     */
    public List<Integer> getCatLotIdByContractId(Integer contractId) {
        Map<String, Object> map = Maps.newLinkedHashMap();
        StringBuffer sql = new StringBuffer("select yx.car_lot_id ");
        sql.append("from yx_car_lot yx  where yx.contract_id = :contractId  ");
        map.put("contractId", contractId);
        return (List<Integer>) this.findSqlObject(sql.toString(), map);
    }
}